using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Globalization;
using System.IO;
using System.Security.Principal;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.LearningComponents;
using Microsoft.LearningComponents.Storage;
using Schema = BasicWebPlayer.Schema;
using LearningComponentsHelper;
public partial class SequencingLog : BasicWebPlayerBase
{
protected void Page_Load(object sender, EventArgs e)
{
AttemptItemIdentifier attemptId = new AttemptItemIdentifier(
Convert.ToInt64(Request.QueryString["AttemptId"], CultureInfo.InvariantCulture));
long previousEntryId;
string value = Request.QueryString["PreviousEntryId"];
if (value == null)
previousEntryId = long.MaxValue;
else
previousEntryId = Convert.ToInt64(value, CultureInfo.InvariantCulture);
try
{
LearningStoreJob job = LStore.CreateJob();
LearningStoreQuery query = LStore.CreateQuery(Schema.MyAttemptsAndPackages.ViewName);
query.AddColumn(Schema.MyAttemptsAndPackages.PackageFileName);
query.AddColumn(Schema.MyAttemptsAndPackages.OrganizationTitle);
query.AddCondition(Schema.MyAttemptsAndPackages.AttemptId,
LearningStoreConditionOperator.Equal, attemptId);
job.PerformQuery(query);
query = LStore.CreateQuery(Schema.SequencingLog.ViewName);
query.AddColumn(Schema.SequencingLog.Id);
query.AddColumn(Schema.SequencingLog.Timestamp);
query.AddColumn(Schema.SequencingLog.EventType);
query.AddColumn(Schema.SequencingLog.NavigationCommand);
query.AddColumn(Schema.SequencingLog.Message);
query.SetParameter(Schema.SequencingLog.AttemptId, attemptId);
query.AddSort(Schema.SequencingLog.Id,
LearningStoreSortDirection.Descending);
job.PerformQuery(query);
ReadOnlyCollection<object> results = job.Execute();
DataTable attemptInfoDataTable = (DataTable)results[0];
DataTable sequencingLogDataTable = (DataTable)results[1];
DataRow attemptInfo = attemptInfoDataTable.Rows[0];
string packageFileName;
LStoreHelper.CastNonNull(attemptInfo[Schema.MyAttemptsAndPackages.PackageFileName],
out packageFileName);
string organizationTitle;
LStoreHelper.CastNonNull(attemptInfo[Schema.MyAttemptsAndPackages.OrganizationTitle],
out organizationTitle);
string trainingName;
if (organizationTitle.Length == 0)
trainingName = packageFileName;
else
trainingName = String.Format("{0} - {1}", packageFileName, organizationTitle);
TrainingName.Text = Server.HtmlEncode(trainingName);
SequencingLogEntryItemIdentifier maxLogEntryId;
if (sequencingLogDataTable.Rows.Count > 0)
{
DataRow dataRow = sequencingLogDataTable.Rows[0];
LStoreHelper.CastNonNull(dataRow[Schema.SequencingLog.Id],
out maxLogEntryId);
}
else
maxLogEntryId = new SequencingLogEntryItemIdentifier(-1);
foreach (DataRow dataRow in sequencingLogDataTable.Rows)
{
SequencingLogEntryItemIdentifier logEntryId;
LStoreHelper.CastNonNull(dataRow[Schema.SequencingLog.Id],
out logEntryId);
DateTime? time;
LStoreHelper.Cast(dataRow[Schema.SequencingLog.Timestamp],
out time);
SequencingEventType? eventType;
LStoreHelper.Cast(dataRow[Schema.SequencingLog.EventType],
out eventType);
NavigationCommand? navigationCommand;
LStoreHelper.Cast(dataRow[Schema.SequencingLog.NavigationCommand],
out navigationCommand);
string message;
LStoreHelper.CastNonNull(dataRow[Schema.SequencingLog.Message],
out message);
TableRow htmlRow = new TableRow();
if (logEntryId.GetKey() > previousEntryId)
htmlRow.CssClass = "Highlight";
TableCell htmlCell = new TableCell();
htmlCell.CssClass = "Id_";
htmlCell.Wrap = false;
htmlCell.Text = NoBr(Server.HtmlEncode(logEntryId.GetKey().ToString()));
htmlRow.Cells.Add(htmlCell);
htmlCell = new TableCell();
htmlCell.CssClass = "Time_";
htmlCell.Wrap = false;
htmlCell.Text = NoBr(Server.HtmlEncode(String.Format("{0:d} {0:t}", time)));
htmlRow.Cells.Add(htmlCell);
htmlCell = new TableCell();
htmlCell.CssClass = "EventType_";
htmlCell.Wrap = false;
htmlCell.Text = NoBr(Server.HtmlEncode(eventType.ToString()));
htmlRow.Cells.Add(htmlCell);
htmlCell = new TableCell();
htmlCell.CssClass = "NavigationCommand_";
htmlCell.Wrap = false;
htmlCell.Text = NoBr(Server.HtmlEncode(navigationCommand.ToString()));
htmlRow.Cells.Add(htmlCell);
htmlCell = new TableCell();
htmlCell.CssClass = "Message_";
htmlCell.Wrap = false;
htmlCell.Text = Server.HtmlEncode(message);
htmlRow.Cells.Add(htmlCell);
LogGrid.Rows.Add(htmlRow);
}
RefreshLink.NavigateUrl = String.Format("?AttemptId={0}&PreviousEntryId={1}",
attemptId.GetKey(), maxLogEntryId.GetKey());
}
catch (Exception ex)
{
LogTitle.Visible = false;
LogContents.Visible = false;
ErrorMessage.Visible = true;
ErrorMessage.Controls.Add(new System.Web.UI.LiteralControl(
Server.HtmlEncode("A serious error occurred. Please contact your system administrator. More information has been written to the server event log.")));
LogEvent(System.Diagnostics.EventLogEntryType.Error,
"An exception occurred while accessing the sequencing log for attempt #{0}:\n\n{1}\n\n",
attemptId.GetKey(), ex.ToString());
}
}
}